/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.statemachine.editpart;

import org.eclipse.draw2d.ConnectionLayer;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ShortestPathConnectionRouter;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.LayerConstants;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editpart.DiagramEditPart;
import com.cea.papyrus.core.editpart.DimensionAdaptationEditPolicy;
import com.cea.papyrus.core.editpart.IUMLDiagramElementEditPart;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;

/**
 * The Class StateMachineDiagramEditPart.
 * Manages model of a stateMachineDiagram.
 * Redefines the DiagramEditPart of classdiagram package with
 * new edit policy for connection in StateMachine diagrams.
 * 
 * @author David Servat
 * @since 29 jan. 07
 * 
 */
public class StateMachineDiagramEditPart extends DiagramEditPart implements LayerConstants, IUMLDiagramElementEditPart{

	/**
	 * The channel.
	 */
	private int channel = 501;

	/**
	 * The element that is associated is Diagram.
	 * 
	 * @param modelManager the model manager
	 * @param diagram the diagram
	 */
	public StateMachineDiagramEditPart(Diagram diagram, ModelManager modelManager){
		super(diagram, modelManager);

		Debug.debug(this,"StateMachineDiagramEditPart(Diagram diagram, ModelManager mmodelManager)", channel);
	}

	/**
	 * Installs EditPolicies specific to this. 
	 */
	@Override
	protected void createEditPolicies(){
		super.createEditPolicies();
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new StateMachineLayoutEditPolicy((XYLayout)getContentPane().getLayoutManager()));
        // AdaptDimensionEditPolicy
        installEditPolicy(DimensionAdaptationEditPolicy.DIMENSION_ADAPTATION, new ContainerDimensionAdaptationEditPolicy());
	}

	/**
	 * Returns a Figure to represent this. 
	 * 
	 * @return  Figure.
	 */
	@Override
	protected IFigure createFigure(){
		IFigure f = super.createFigure();
		ConnectionLayer connLayer = (ConnectionLayer)getLayer(LayerConstants.CONNECTION_LAYER);
		connLayer.setConnectionRouter(new ShortestPathConnectionRouter(f));			
		return f;
	}
}
